#include "stdafx.h"
#include "MCVector.h"


MCVector::MCVector()
{
	x=0.0;
	y=0.0;
	z=0.0;
	val=0.0;
}

MCVector::MCVector(float x_, float y_, float z_)
{
	x=x_;
	y=y_;
	z=z_;
	val=0.0;
}

MCVector::MCVector(float x_, float y_, float z_, float val_)
{
	x=x_;
	y=y_;
	z=z_;
	val=val_;
}

MCVector::MCVector(const MCVector& v)
{
	x=v.x;
	y=v.y;
	z=v.z;
	val=v.val;
}

MCVector MCVector::operator + (MCVector v)
{
	return MCVector(x+v.x, y+v.y, z+v.z);
}

MCVector MCVector::operator - (MCVector v)
{
	return MCVector(x-v.x, y-v.y, z-v.z);
}

float MCVector::operator * (MCVector v)
{
	return (x*v.x+y*v.y+z*v.z);
}

MCVector MCVector::CrossProduct(const MCVector& v)
{
	return MCVector(y*v.x-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
}

MCVector MCVector::operator + (float k)
{
	return MCVector(x+k, y+k, z+k);
}

MCVector MCVector::operator - (float k)
{
	return MCVector(x-k, y-k, z-k);
}

MCVector MCVector::operator / (float k)
{
	if (k!=0)
		return MCVector(x/k, y/k, z/k);
	else
		return *this;
}

MCVector MCVector::operator * (float k)
{
	return MCVector(x*k, y*k, z*k);
}

MCVector& MCVector::operator = (const MCVector& v)
{
	//deep copy
	x=v.x;
	y=v.y;
	z=v.z;
	val=v.val;
	return MCVector(x,y,z,val);
}

float MCVector::Magnitude()
{
	return sqrt(x*x+y*y+z*z);
}

MCVector& MCVector::Normalize()
{
	float length = sqrt(x*x + y*y + z*z);
	if(!length) return *this;
	x /= length;
	y /= length;
	z /= length;
	return *this;
}